<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/22
 * Time: 9:55
 */

namespace app\merchant\controller;

use app\home\model\HomeModule;

use app\home\model\HomeTemplate;
use app\Request;


class Module
{


    public function moduleList(Request $request)
    {
        $param = $request->param();
        $moduleModel = new HomeModule();

        $where['template_id'] = $param['template_id'];
        if (isset( $param['template_id']) && !empty($param['template_id']) ){
            $where['template_id'] = $param['template_id'];
        }
        $data = $moduleModel->order('sort', 'asc')->where($where)->where(['type' => $param['type']])->select()->toArray();
        $count = $moduleModel->order('sort', 'asc')->where($where)->where(['type' => $param['type']])->count();
        return adminSuccess('模块', ['list' => $data,'count' => $count]);
    }

    public function upModuleStatus(Request $request)
    {
        $param = $request->param();
        $homeTemplateModel = new HomeModule();
        $homeTemplateModel->where(['id' => $param['id']])->update(['status' => $param['status']]);
        return success('修改成功');
    }

    public function editModule(Request $request)
    {
        $param = $request->param();
        $homeTemplateModel = new HomeModule();
        $data =
            [
                'name' => $param['name'],
                'icon' => $param['icon'],
                'link' => $param['link'],
                'sort' => $param['sort'],
                'desc' => $param['desc'],
                'update_time' => time()
            ];
        $homeTemplateModel->where(['id' => $param['id']])->update($data);
        return success('修改成功');
    }
}